{layout name="master" /}

<form action="javascript:;" method="post" role="form">
    <legend>欢迎发表文章</legend>

    <div class="form-group">
        <label for="">文章标题</label>
        <input type="text" class="form-control" name="title"  placeholder="请输入标题">
    </div>
    <div class="form-group">
        <label for="">所属分类</label>
        <select name="cid"  class="form-control">
            <option value=""> -- Select One -- </option>
            {volist name="category" id="vo"}
             <option value="{$vo['cid']}"> {$vo['cname']}</option>
            {/volist}
        </select>
    </div>
    <div class="form-group">
        <label for="">选择标签 &nbsp;&nbsp;&nbsp;</label>
        {volist name="tags" id="vo"}
        	<label>
        		<input type="checkbox" name="tid[]" value="{$vo['tid']}" >
                {$vo['tname']}
        	</label>
        {/volist}
    </div>


    <script id="editor" type="text/plain" style="width:598px;height:500px;margin-bottom:5px"></script>
    <a href="{:url('index')}" class="btn btn-primary">发微博</a>
    <button type="submit" onclick="hasContent()" class="btn btn-success">发文章</button>

</form>

<script>
    toolbars = [[
        'fullscreen', 'source', '|', 'undo', 'redo', '|',
        'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
        'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
        'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
        'directionalityltr', 'directionalityrtl', 'indent', '|',
        'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
        'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
        'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
        'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
        'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
        'print', 'preview', 'searchreplace', 'drafts', 'help'
    ]];
    var ue = UE.getEditor('editor', toolbars);
    function hasContent() {
        var data = $('form').serialize();
        if (!UE.getEditor('editor').hasContents()) {
            alert('请填写内容');
        } else {
            $.ajax({
                type: "POST",
                url: "{:url('pubarc')}",
                data: data,
                dataType: "json",
                success: function (msg) {
                  if(msg){
                      alert('发表成功');
                     location.href="{:url('index')}";
                  }else{
                      alert('发表失败')
                  }
                }
            })
        }
    }

</script>